<!DOCTYPE html>
<html lang="en" class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Edit Storage</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="stylesheet" th:href="@{/css/font.css}">
<link rel="stylesheet" th:href="@{/css/xadmin.css}">
<script type="text/javascript" th:src="@{/lib/layui/layui.js}"
	charset="utf-8"></script>
<script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
</head>
<body>
	<div class="layui-fluid">
		<div class="layui-row">
			<form class="layui-form">
				<div class="layui-form-item" style="display: none">
					<label for="providerNo" class="layui-form-label"> <span
						class="x-red">*</span>供应商编号
					</label>
					<div class="layui-input-inline">
						<input type="text" id="providerNo" name="providerNo" required=""
							lay-verify="providerNo" autocomplete="off" class="layui-input"
							th:value="${provider.providerNo}">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="provider" class="layui-form-label"> <span
						class="x-red">*</span>供应商名称
					</label>
					<div class="layui-input-inline">
						<input type="text" id="provider" name="provider" required=""
							lay-verify="provider" autocomplete="off" class="layui-input"
							th:value="${provider.provider}">
					</div>
					<div class="layui-form-mid layui-word-aux">
						<span class="x-red">*</span>将会成为您唯一的供应商名称
					</div>
				</div>

				<div class="layui-form-item">
					<label for="providerAddress" class="layui-form-label">供应商地址</label>
					<div class="layui-input-inline">
						<input type="text" id="providerAddress" name="providerAddress"
							required="" lay-verify="providerAddress" autocomplete="off"
							class="layui-input" th:value="${provider.providerAddress}">
					</div>
				</div>

				<div class="layui-form-item">
					<label for="providerPhone" class="layui-form-label"> <span
						class="x-red">*</span>供应商联系方式
					</label>
					<div class="layui-input-inline">
						<input type="text" id="providerPhone" name="providerPhone"
							required="" lay-verify="phone" autocomplete="off"
							class="layui-input" th:value="${provider.providerPhone}">
					</div>
				</div>

				<div class="layui-form-item">
					<label for="charge" class="layui-form-label"> <span
						class="x-red">*</span>供应商负责人
					</label>
					<div class="layui-input-inline">
						<input type="text" id="charge" name="charge" required=""
							lay-verify="charge" autocomplete="off" class="layui-input"
							th:value="${provider.charge}">
					</div>
				</div>

				<div class="layui-form-item">
					<label for="chargePhone" class="layui-form-label"> <span
						class="x-red">*</span>负责人联系方式
					</label>
					<div class="layui-input-inline">
						<input type="text" id="chargePhone" name="chargePhone" required=""
							lay-verify="phone" autocomplete="off" class="layui-input"
							th:value="${provider.chargePhone}">
					</div>
				</div>

				<div class="layui-form-item">
					<label for="L_repass" class="layui-form-label"></label>
					<button id="L_repass" class="layui-btn" lay-filter="edit"
						lay-submit="">修改</button>
				</div>
			</form>
		</div>
	</div>
	<script>
		layui.use([ 'form', 'layer', 'jquery', 'upload' ], function() {
			$ = layui.jquery;
			const form = layui.form, layer = layui.layer;

			//自定义验证规则
			form.verify({
				userName : function(value) {
					if (value.length > 1) {
						return '昵称至少得1个字符啊';
					}
				}
			});

			//监听提交
			form.on('submit(edit)', function(data) {
				console.log(data.field)
				$.ajax({
					url : "/provider/edit",
					method : 'post',
					data : data.field,
					dataType : 'JSON',
					success : function(res) {
						if (res.code === 0) {
							//弹出提示，并在1秒后进行跳转
							layer.alert("修改成功", {
								icon : 6
							}, function() {
								//关闭当前frame
								xadmin.close();
								// 可以对父窗口进行刷新
								xadmin.father_reload();
								return false;
							});
						} else {
							layer.msg("修改失败:" + res.msg);
							return false;
						}
					}
				});
				return false;
			});
		})
	</script>
</body>
</html>
